package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.DistrictDao;
import com.ChenYaRou.www.po.District;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName DistrictDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 22:43
 * @Version 1.0
 **/
public class DistrictDaoImpl implements DistrictDao {
    /**
     * 查找所有district信息
     * @param district 这个其实没有用,可以不要的,district
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<District> select(District district) throws IllegalAccessException, SQLException,
            NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().selectAll(new District()),District.class);
    }

    /**
     * 查询单个district
     * @param district
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public District selectSingle(District district) throws IllegalAccessException, SQLException,
            NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectSimple(GenerateSql.getInstance().select(district),District.class);
    }

    /**
     * 更新district信息
     * @param newDistrict district需要更新的值
     * @param  oldDistrict old district
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(District newDistrict, District oldDistrict) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newDistrict,oldDistrict));
    }

    /**
     * 插入district信息
     * @param district 新district
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(District district) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(district));
    }
}
